package com.milk.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.milk.system.common.result.Result;
import com.milk.system.model.dto.CaptchaResult;
import com.milk.system.model.dto.LoginResult;
import com.milk.system.model.entity.SysUser;
import com.milk.system.model.vo.UserVO;
import com.milk.system.security.util.SecurityUtils;
import com.milk.system.service.AuthService;
import com.milk.system.service.SysUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@Tag(name = "个人信息")
@RestController
@RequestMapping("/api/userinfo")
@RequiredArgsConstructor
@Slf4j
@Valid
public class userInfoController {

    @Resource
    private  SysUserService userService;



    @Operation(summary = "获取个人信息")
    @GetMapping("/getUserInfo")
    public Result<UserVO> UserInfo() {
        UserVO userVO = userService.UserInfo();
        return Result.success(userVO);
    }

    @Operation(summary = "修改用户密码")
    @PatchMapping(value = "/{userId}/password")
    public Result updatePassword(@NotNull String oldPassword, @NotNull String newPassword) {
        boolean result = userService.updateUserPassword(oldPassword, newPassword);
        return Result.judge(result);
    }

}
